package com.waimai.service;

import java.awt.Toolkit;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.waimai.dao.UserDao;
import com.waimai.dao.UserDao2;
import com.waimai.model.User;

@Repository("userservice")
public class UserService {

	private boolean flag = true;
	@Resource(name = "userdao")
	private UserDao userDao;

	@Resource(name = "userdao2")
	private UserDao2 userdao2;

	public List<User> getAll() {
		String sql = "select * from user";
		if (flag)
			return userdao2.findAll(sql);
		return userDao.findAll(sql);
	}

	public static void changeFlag() {
		Thread t = new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub

			}
		});
	}

	Timer timer;
	Toolkit toolkit;

	public void Reminder(int seconds) {
		toolkit = Toolkit.getDefaultToolkit();
		timer = new Timer();
		timer.schedule(new RemindTask(), 0, seconds * 1000);
	}

	class RemindTask extends TimerTask {
		int numWarningBeeps = 3;

		public void run() {
			if (flag) {
				flag = false;
				System.out.println("Beep!");
			} else {
				flag = true;
			}
		}
	}
}
